package com.example.opensdkdemo;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import cn.com.cetccst.sdk.modelbase.BaseResp;
import cn.com.cetccst.sdk.modelbiz.SendAuth;
import cn.com.cetccst.sdk.openapi.ISSAPI;
import cn.com.cetccst.sdk.openapi.SSAPIFactory;

public class MainActivity extends AppCompatActivity {

    private ISSAPI api;
    public final static String APPKEY = "THIRDAPP_TEST_123456789";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        api = SSAPIFactory.getInstance(this, APPKEY);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
    }

    public void login(View view) {
        SendAuth.Req req = new SendAuth.Req();
        api.sendReq(req, (ISSAPI.IResponseListener<SendAuth.Resp>) resp -> {
            if (resp.errorCode == BaseResp.ErrCode.ERR_OK) {
                Toast.makeText(this, "获取 oauthCode ： " + resp.oAuthCode, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, "获取 oauthCode 失败 ： " + resp.errorStr, Toast.LENGTH_SHORT).show();
            }

        });
    }
}